package com.example.backend.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;

/**
 * @Description TODO
 * @Author CDHong
 * @Date Created in 2024/10/23 10:10
 * @Version 1.0
 */
public class MyBatisPlusCodeGenerator {
    public static void main(String[] args) {
        FastAutoGenerator
                .create("jdbc:mysql://localhost:3306/login", "root", "123456")
                .globalConfig(builder -> builder
                        .author("zyl.it")
                        // .enableSwagger() // 开启 swagger 模式
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .commentDate("yyyy-MM-dd")
                        .disableOpenDir() // 禁止打开输出目录
                )
                .packageConfig(builder -> builder
                                .parent("com.example.backend")
                                .entity("entity")
                                .mapper("mapper")
                                .service("service")
                                .serviceImpl("service.impl")
                                .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                                .entityBuilder().enableLombok().enableFileOverride()
                                .controllerBuilder().enableFileOverride()
                                .mapperBuilder().enableFileOverride()
                                .serviceBuilder().enableFileOverride()
                                .build()

                        //.addInclude("tbl_user") // 设置需要生成的表名
                        //.addTablePrefix("tbl_", "c_") // 设置过滤表前缀
//                        .entityBuilder()
//                        .enableTableFieldAnnotation()
//                        .enableRemoveIsPrefix()
//                        .enableLombok()
//                        .controllerBuilder().enableRestStyle().enableHyphenStyle()  // 开启生成@RestController 控制器，使用驼峰转连字符
                )
                .templateEngine(new FreemarkerTemplateEngine())  // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
